home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_01_05 / 1n05012a < prev    next >
Text File  |  1990-08-21  |  4KB  |  127 lines

  1. /*#pragma cc .chc */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <msdos.cf>
  6.  
  7. /* call 8514/A AI from protected mode */
  8.  
  9. int c8514(nentry,pqbl)
  10. int nentry; /* number of entry to call */
  11. char *pqbl; /* parameter block */
  12. /* returns nonzero if call cannot be made */
  13.  
  14. {
  15. /* codes needing special treatment */
  16. #define HQDPS 31 /* query drawing process state size */
  17. #define HINIT 48 /* initialize state */
  18. #define HSYNC 49 /* synchronize adapter */
  19. #define HLDPAL 19 /* load pallette */
  20.  
  21. #define MAXBLK 20 /* maximum parameter block size */
  22.  
  23.   /* real mode interrupt parameters */
  24.   static struct {
  25.     short jint,jds,jes,jfs,jgs; long heax,hedx;
  26.   } i_rmipas = {0x7E,0,0,0,0,0,0};
  27.  
  28.   static int linit = 0;
  29.   static int iszbuf,lentsb,limbys,numbys,maxbys;
  30.  
  31.   static char _far *pqdbuf; /* real mode buffer */
  32.   static char _far *pqpa;   /* real mode parameter */
  33.  
  34.   int kt,lnth;
  35.  
  36.   /* initialize first time */
  37.   if (!linit) {
  38.  
  39.     /* p8514 must be loaded - check 0x7E interrupt */
  40.     Registers.AX.W = 0x2503;
  41.     Registers.CX.W = 0x7E;
  42.     calldos();
  43.     if (Registers.BX.W == 0) return (2);
  44.  
  45.     /* initialize p8514 - do an int 0x7E */
  46.     i_rmipas.heax = 0;
  47.     Registers.AX.W = 0x2511;
  48.     Registers.DX.R = (long)&i_rmipas;
  49.     Registers.DS.W = 0x0014;
  50.     calldos();
  51.     if (Registers.AX.W != 0) return (1);
  52.  
  53.     /* get address of real mode buffer */
  54.     *(long *)&pqdbuf = (Registers.CX.W << 4)+
  55.                        Registers.BX.W;
  56.     ((short *)&pqdbuf)[2] = 0x0034;
  57.  
  58.     /* first two bytes have the length of the rest */
  59.     iszbuf = *(short _far *)pqdbuf;
  60.     pqdbuf += 2;
  61.  
  62.     lentsb = 0; /* length of task state buffer */
  63.     maxbys = iszbuf; /* bytes to use for commands */
  64.     limbys = maxbys; /* current limit for commands */
  65.     numbys = 0; /* bytes currently in buffer */
  66.     linit = 1; /* initialization done */
  67.   }
  68.  
  69.   if (nentry >= 0) { /* do command if any */
  70.  
  71.     /* get the parameter block and check length */
  72.     lnth = *(short *)pqbl+2;
  73.     if (lnth > MAXBLK) {
  74.       printf("parameter block too long\n");
  75.       exit(1);
  76.     }
  77.  
  78.     /* put the command in front of the block */
  79.     pqdbuf[numbys++] = nentry;
  80.  
  81.     /* now copy the block into the real mode buffer */
  82.     pqpa = pqdbuf+numbys;
  83.     for (kt = 0; kt < lnth; kt++) pqpa[kt] = pqbl[kt];
  84.     numbys += lnth;
  85.  
  86.     /* some codes get segment of task state buffer */
  87.     if (nentry == HINIT || nentry == HSYNC) {
  88.       *(short _far *)(pqpa+2) =
  89.                 (*(long *)&pqdbuf+iszbuf-lentsb) >> 4;
  90.     }
  91.  
  92.     /* set up color values for load palette command */
  93.     if (nentry == HLDPAL && lnth == 12) {
  94.       limbys -= 4;
  95.       *(short _far *)(pqpa+8) =
  96.                   (*(long *)&pqdbuf+limbys) & 0x000F;
  97.       *(short _far *)(pqpa+10) =
  98.                   (*(long *)&pqdbuf+limbys) >> 4;
  99.       for (kt = 0; kt < 4; kt++) {
  100.         pqdbuf[limbys+kt] = (*(char **)(pqbl+8))[kt];
  101.       }
  102.     }
  103.   }
  104.   /* call the adapter interface in some cases */
  105.   if (nentry == HQDPS || nentry < 0 && numbys > 0 ||
  106.       numbys+MAXBLK >= limbys) {
  107.  
  108.     /* call the adapter interface (int 0x7E) */
  109.     i_rmipas.heax = numbys;
  110.     Registers.AX.W = 0x2511;
  111.     Registers.DX.R = (long)&i_rmipas;
  112.     Registers.DS.W = 0x0014;
  113.     calldos();
  114.  
  115.     /* get state buffer length and make a local one */
  116.     if (nentry == HQDPS) {
  117.       *(short *)&pqbl[2] = *(short _far *)&pqpa[2];
  118.       lentsb = *(short *)&pqbl[2];
  119.       maxbys = iszbuf-lentsb-15;
  120.     }
  121.  
  122.     numbys = 0; /* begin buffer next time */
  123.     limbys = maxbys; /* reset bytes for commands */
  124.   }
  125.   return (0);
  126. }
  127.